package com.softcits.email.common;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.catalina.connector.ClientAbortException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class EmailExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Object handleException(Exception e, HttpServletRequest request, HttpServletResponse response){

        if(e instanceof ClientAbortException) {
            return null;
        }
        //logger.error("请求：{}发生异常：{}", request.getRequestURI(), e);

        ErrorInfo<String> result = new ErrorInfo<>();
        result.setCode(ErrorInfo.ERROR);
        result.setMessage(e.getMessage());
        result.setData("Exception Handler:");
        result.setUrl(request.getRequestURL().toString());

        return result;
    }
}